/**
 * Assignment 5                   P5.java                  Due July 20, 2011
 *
 * login: cs11ubn
 */

import java.util.Scanner;

/**
 * Driver class for P5
 */
public class P5
{
  // Array of the shapes
  private static P5Shape[] a;

  /**
   * Main method called by java P5
   */
  public static void main(String[] args)
  {
    // Declare our local variables
    char choice; // Holds a letter. If n or N then exit
    double rad, cyl_height, width, height, depth; // Values from user input
    Scanner scan = new Scanner(System.in); // Scanner for input
    String inputStr = null; // Holds the raw input

    // Setup our array of shapes
    a = new P5Shape[4];
    a[0] = new P5Circle(); // Make a no-arg circle
    a[1] = new P5Cylinder(2, 3); // Make a cylinder with the given h and r
    a[2] = new P5Rectangle(); // Make a no-arg rectangle
    a[3] = new P5Box(2, 3, 4); // Make a box with the given h, d, w
    prt(); // Print them out to the console

    // Loop for more input
    do
    {
      // Prompt for cylinder input. Use this input for the circle too
      System.out.print("\nEnter CYLINDER (radius height): ");
      rad = scan.nextDouble(); // Get the radius
      cyl_height = scan.nextDouble(); // Get the height

      // Prompt for box input. Use this input for the rectangle too
      System.out.print("Enter BOX (width height depth): ");
      width = scan.nextDouble(); // Get the width
      height = scan.nextDouble(); // Get the height
      depth = scan.nextDouble(); // Get the depth

      // Make our new objects and store them in the array
      a[0] = new P5Circle(rad); // Circle with the given r
      a[1] = new P5Cylinder(rad, cyl_height); // Cylinder with the given r, h
      a[2] = new P5Rectangle(width, height); // Rectangle with the given w, h
      a[3] = new P5Box(width, height, depth); // Box with the given w, h, d
      prt(); // Print them out

      // Prompt for continue
      System.out.print("\nWould you like to compute area (y/n)? ");
      inputStr = scan.next(); // Get the input
      choice = inputStr.charAt(0); // Get the first char
    } while(choice != 'n' && choice != 'N'); // While the char is not n nor N
  }

  /**
   * Function to print and format the arrays objects toString methods.
   */
  public static void prt()
  {
    // First object (Circle)
    System.out.print(a[0] + "\thas an area: ");
    System.out.printf("%.2f\n", a[0].area());

    // Second object (Cylinder)
    System.out.print(a[1] + "\thas a surface area: ");
    System.out.printf("%.2f", a[1].area());
    System.out.print(" \tvolume ");
    System.out.printf("%.2f\n", a[1].volume());

    // Third object (Rectangle)
    System.out.print(a[2] + "\thas an area: ");
    System.out.printf("%.2f\n", a[2].area());

    // Fourth object (Box)
    System.out.print(a[3] + "\thas a surface area: ");
    System.out.printf("%.2f", a[3].area());
    System.out.print(" \tvolume ");
    System.out.printf("%.2f\n", a[3].volume());
  }
}
